import { wechatrequest } from './API/request'
import { getStorageSync } from '../crossplatform/apiservice/storage'

/**
 *  职位收藏列表
 * */
export const getCollectionList = () => {
  const landmark = getStorageSync('landmark')
  let data = {}
  // 计算距离
  if (landmark.lng && landmark.lat) {
    data.latitude = landmark.lat
    data.longitude = landmark.lng
  }
  return wechatrequest.post('@@/post/postCollectionList', {
    data: {
      ...data
    }
  })
}

/**
 * 查询招聘者收藏的人才
 * */
export const queryportGetPeople = () => {
  const userinfo = getStorageSync('userinfo') || {}
  const userId = userinfo.userId
  return wechatrequest.put(`@@/userArchive/findUserArchiveByUserId`, {
    data: { userId }
  })
}

/**
 * 收藏简历
 */
export const insertArchiveRequest = ({ archiveId, userId }) => {
  return wechatrequest.put('/userArchive/insertArchiveCollection', {
    data: { archiveId, userId }
  })
}

/**
 *收藏职位
 */
export const insertPostRequest = ({ postId }) => {
  const userinfo = getStorageSync('userinfo') || {}
  const userId = userinfo.zhichuUserId
  return wechatrequest.postform('/post/collectionPost', {
    data: { postId, userId }
  })
}

/**
 * 删除一份收藏的简历
 */
export const removeArchiveRequest = ({ archiveIds = [] }) => {
  const userinfo = getStorageSync('userinfo') || {}
  const userId = userinfo.userId
  return wechatrequest.postform('/userArchive/removeArchiveCollection', {
    data: { archiveIds: archiveIds.join(','), userId }
  })
}

/**
 * 删除一份收藏的职位
 */
export const removePostRequest = ({ ids = [] }) => {
  return wechatrequest.postform('/post/cancelCollectionPost', {
    data: { ids: ids.join(',') }
  })
}
